﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLDC.Common.Estate;
using System.Text;
using System.Data;

namespace ZLDC.Estate.TM
{
    public partial class NewsAdd : _PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            btnSave.Attributes.Add("onclick", "javascript:return Data();");
            if (!IsPostBack)
            {
                int id = _Request.GetInt("id", 0);
                if (id > 0)
                {
                    DataSet ds = ZLDC.Topo.BLL.Estate.NewsBLL.p_list_Details(id);
                    FreeTextBox1.Text = ds.Tables[0].Rows[0]["content"].ToString();
                    txtTitle.Text = ds.Tables[0].Rows[0]["title"].ToString();

                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        if (ds.Tables[0].Rows[0]["ispop"].ToString() == "1")
                        {
                            isShow.Checked = true;
                        }
                    }
                        
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string content = FreeTextBox1.Text.Trim().ToString().Replace("'", "''"); //内容
            string title = txtTitle.Text.Trim();//标题
            int ispop = 0;
            if (isShow.Checked)
            {
                ispop = 1;
            }
            

            string condition = "";
            int id = _Request.GetInt("id", 0);
            if (id > 0)///修改公告
            {
                if (content != "" && title != "")
                {
                    condition = " title='" + title + "', content='" + content + "',ispop='"+ispop+"' ";

                    string outmsg = ZLDC.Topo.BLL.Estate.NewsBLL.UpdateNews(id,condition);
                    _Utility.GoError(outmsg);
                   // Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('" + outmsg + "')</script>");

                }
            }
            else ///添加公告
            {
                if (content != "" && title != "")
                {
                    condition = "insert into t_news(title,content,pubdate,pubusername,pubuserid,dltflg,ispop) values('" + title + "','" + content + "',getDate(),'" + _Utility.GetInfoBySession().m_sUserName + "'," + _Utility.GetInfoBySession().m_sUserID + ",0,"+ispop+")";
                }
                string outmsg = ZLDC.Topo.BLL.Estate.NewsBLL.InsertNews(condition);
                _Utility.GoError(outmsg);
                // Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('" + outmsg + "')</script>");
            }
        }

        protected void btnCancle_Click(object sender, EventArgs e)
        {
            FreeTextBox1.Text = "";
            txtTitle.Text = "";
        }
    }
}
